package com.zy.cat.entity.dev.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.zy.cat.entity.dev.CatDevZJInviteIncomeHistory;
 
public interface CatDevZJInviteIncomeHistoryRepository extends JpaSpecificationExecutor<CatDevZJInviteIncomeHistory>,  JpaRepository<CatDevZJInviteIncomeHistory, String>{
 
	CatDevZJInviteIncomeHistory findByPidAndYidAndIstatusAndItype(String pid,String yid,int istatus,int itype);
	/**
	 * 
	 * @info 获取被邀请人的奖励信息
	 * @author Link
	 * @date 2019-11-28 19:57
	 * @param pid
	 * @return
	 */
	@Query("from CatDevZJInviteIncomeHistory where pid=:pid and CURDATE()>=stime and etime>=NOW() and istatus=1")
	List<CatDevZJInviteIncomeHistory> findZJInviteInfo(@Param("pid")String pid);

	/**
	 * 
	 * @info 获取被邀请人的打开APP任务
	 * @author Link
	 * @date 2019-11-28 19:57
	 * @param pid
	 * @return
	 */
	@Query(value ="select * from zy_cat_user_zj_invite_income_data where pid=:pid AND istatus=0 AND itype!=4 AND CURDATE()>=stime AND etime>=NOW() AND date_add(CURDATE(), interval -(itype-1) day)>=stime ORDER BY itype LIMIT 1",nativeQuery=true)
	CatDevZJInviteIncomeHistory findZJInviteOpenTaskHistory(@Param("pid")String pid);
	
	/**
	 * 判断今日是否已领取打开应用任务
	 * @author lipengchao
	 * @date 2019-12-10 10:34:55
	 * @param pid
	 * @return
	 */
	@Query(value = "select * from zy_cat_user_zj_invite_income_data where pid=:pid and istatus=1 and itype!=4 and CURDATE()>=stime and etime>=NOW() and ltime>=CURDATE() ORDER BY ltime DESC LIMIT 1",nativeQuery=true)
	CatDevZJInviteIncomeHistory findZJInviteLast(@Param("pid")String pid);
	
	CatDevZJInviteIncomeHistory findByPidAndItypeAndIstatus(@Param("pid")String pid,int itype,int istatus);
}
